﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

using CE.User;

public partial class user_UserMessage : System.Web.UI.Page
{
    protected string _header;
    protected string _body;
    protected string _footer;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.Params["errorcode"] != null)
            {
                string _errcode = Request.Params["errorcode"].ToString();

                GetMessage(_errcode);
                lblMessageHeader.Text = _header;
                lblMessageBody.Text = _body;
                lblMessageFooter.Text = _footer;
            }

            if (Request.Params["mt"] != null && Request.Params["ec"] != null)
            {
                string _messagetype = Request.Params["mt"].ToString();
                Int32 _errcode = Convert.ToInt32(Request.Params["ec"].ToString());

                //GetMessage(_messagetype, _errcode);
                GetMessage(_errcode.ToString());
                lblMessageHeader.Text = _header;
                lblMessageBody.Text = _body;
                lblMessageFooter.Text = _footer;
            }
            else
            {
                lblMessageHeader.Text = "CompareXpress";
                lblMessageBody.Text = "No message found!";
                lblMessageFooter.Text = "Please <a href = '/'><b>click here</b></a> to <b> Home page</b>.!";
            }

            //back button from email this
            if (Request.UrlReferrer != null)
            {
                if (Request.UrlReferrer.AbsolutePath.ToString().ToLower() == "/car-insurance/email-this.aspx")
                {
                    btnBack.Visible = true;
                }

            }


        }
    }

    private void GetMessage(string MessageType, Int32 ErrorCode)
    {
        MessageDB _messagedb = new MessageDB();
        DataTable _Message = new DataTable();
        _Message = _messagedb.GetMessage(400, MessageType, ErrorCode);
        if (_Message != null && _Message.Rows.Count > 0)
        {
            _header = _Message.Rows[0]["Header"].ToString();
            _body = _Message.Rows[0]["Body"].ToString();
            _footer = _Message.Rows[0]["Footer"].ToString();
        }
        else
        {
            _header = "CompareXpress";
            _body = "No message found!";
            _footer = "Please <a href = '/'><b>click here</b></a> to <b> Home page</b>.!";
        }
    }

    private void GetMessage(string ErrorCode)
    {
        if (ErrorCode == "404")
        {
            _header = "Customer Membership Service";
            _body = "Invalid confirmation key.";
            _footer = "Please contact or request confirmation key.";
        }
        else if (ErrorCode == "100")
        {
            _header = "CompareXpress Membership Service";
            _body = "Thank you very much for choosing our service.";
            _footer = "Please check your registered email account to activate and confirm your account registration.";
        }
        else if (ErrorCode == "200")
        {
            _header = "CompareXpress Membership Service";
            _body = "Your account have been activated. You are ready to use your account, now!";
            _footer = "Please <a href = '../login.aspx'><b>click here</b></a> or <b>Sign In</b> to start requesting our service!";
        }
        else if (ErrorCode == "300")
        {
            _header = "CompareXpress Membership Service";
            _body = "Email confirmation code has been sent to your email address.";
            _footer = "Please <a href = '../login.aspx'><b>click here</b></a> to <b>Sign In</b>.!";
        }
        else if (ErrorCode == "500")
        {
            _header = "CompareXpress Car Insurance Quote";
            _body = "Your request have been sent to your selected provider. You will be contacted by the provider very soon.!";
            _footer = "Please <a href = 'viewresulthistory.aspx?ResultTitle=101'><b>Click Here</b></a> or <b>Car Insurance</b> to view your result history!<br/><br/>";
        }
        else if (ErrorCode == "CI501")
        {
            _header = "CompareXpress Car Insurance Quote";
            _body = "Your car insurance quote and related information have been saved!";
            _footer = "Please <a href = '../login.aspx'><b>click here</b></a> to login again.";
            //ClearCarSession();
        }
        else if (ErrorCode == "CI502")
        {
            _header = "CompareXpress Car Insurance Quote";
            //_body = "Your car insurance result is not valid!";
            _body = "Your car insurance quotes cannot be retrieved and could be due to opening multiple tabs or browsers with the same access.";
            _footer = "Kindly <a href = 'logout.aspx'><b>sign out</b></a> and sign in again.";
            //ClearCarSession();
        }
        else if (ErrorCode == "HF500")
        {
            _header = "CompareXpress Home Loan Service";
            _body = "Your request have been sent to your selected financial institution. You will be contacted by the financial institution company very soon.!";
            _footer = "Please <a href = '/'><b>Click Here</b></a> or <b>Home</b> to go CompareXpress's Home page!<br/><br/>Thanks you very much.";
            //_footer += "<b>Click to send Feed Back :</b> <a href='mailto:kyawthant.phyo@teledirect.com.sg;simmonds.philip@teledirect.com.sg?subject=Car Insurance Feed Back - CompareXpress.com'>Site Admin</a>";
            //_footer += "<b>Click to send Feed Back :</b> <a href='UserFeedBack.aspx'>Site Admin</a>";
        }
        else if (ErrorCode == "PL500")
        {
            _header = "CompareXpress Personal Loans Service";
            _body = "Your request have been sent to your selected financial institution. You will be contacted by the financial institution company very soon.!";
            _footer = "Please <a href = '/'><b>Click Here</b></a> or <b>Home</b> to go CompareXpress's Home page!<br/><br/>Thanks you very much.";
            //_footer += "<b>Click to send Feed Back :</b> <a href='mailto:kyawthant.phyo@teledirect.com.sg;simmonds.philip@teledirect.com.sg?subject=Car Insurance Feed Back - CompareXpress.com'>Site Admin</a>";
            //_footer += "<b>Click to send Feed Back :</b> <a href='UserFeedBack.aspx'>Site Admin</a>";
        }
        else if (ErrorCode == "CC500")
        {
            _header = "CompareXpress Credit Cards Service";
            _body = "Your request have been sent to your selected financial institution. You will be contacted by the financial institution company very soon.!";
            _footer = "Please <a href = '/'><b>Click Here</b></a> or <b>Home</b> to go CompareXpress's Home page!<br/><br/>Thanks you very much.";
            //_footer += "<b>Click to send Feed Back :</b> <a href='mailto:kyawthant.phyo@teledirect.com.sg;simmonds.philip@teledirect.com.sg?subject=Car Insurance Feed Back - CompareXpress.com'>Site Admin</a>";
            //_footer += "<b>Click to send Feed Back :</b> <a href='UserFeedBack.aspx'>Site Admin</a>";
        }
        else if (ErrorCode == "PA500")
        {
            _header = "CompareXpress Personal Accidents Service";
            _body = "Your request have been sent to your selected financial institution. You will be contacted by the financial institution company very soon.!";
            _footer = "Please <a href = '/'><b>Click Here</b></a> or <b>Home</b> to go CompareXpress's Home page!<br/><br/>Thanks you very much.";
            //_footer += "<b>Click to send Feed Back :</b> <a href='mailto:kyawthant.phyo@teledirect.com.sg;simmonds.philip@teledirect.com.sg?subject=Car Insurance Feed Back - CompareXpress.com'>Site Admin</a>";
            //_footer += "<b>Click to send Feed Back :</b> <a href='UserFeedBack.aspx'>Site Admin</a>";
        }
        else if (ErrorCode == "TA500")
        {
            _header = "CompareXpress Travel Insurance Service";
            _body = "Your request have been sent to your selected financial institution. You will be contacted by the financial institution company very soon.!";
            _footer = "Please <a href = '/'><b>Click Here</b></a> or <b>Home</b> to go CompareXpress's Home page!<br/><br/>Thanks you very much.";
            //_footer += "<b>Click to send Feed Back :</b> <a href='mailto:kyawthant.phyo@teledirect.com.sg;simmonds.philip@teledirect.com.sg?subject=Car Insurance Feed Back - CompareXpress.com'>Site Admin</a>";
            //_footer += "<b>Click to send Feed Back :</b> <a href='UserFeedBack.aspx'>Site Admin</a>";
        }
        else if (ErrorCode == "601")
        {
            _header = "CompareXpress Car Insurance Service";
            _body = "Select result history record deleting failed. Please try again later!";
            _footer = "Please <a href = '../car-insurance/profile.aspx'><b>Click Here</b></a> or <b>Car Insurance</b> to start new car insurance quote!<br/><br/>";
            //_footer += "<b>Click to send Feed Back :</b> <a href='mailto:kyawthant.phyo@teledirect.com.sg;simmonds.philip@teledirect.com.sg?subject=Car Insurance Feed Back - CompareXpress.com'>Site Admin</a>";
            //_footer += "<b>Click to send Feed Back :</b> <a href='UserFeedBack.aspx'>Site Admin</a>";
            //ClearCarSession();
        }
        else if (ErrorCode == "101")
        {
            _header = "CompareXpress Car Insurance Quote";
            _body = "Your account session is time out!";
            _footer = "Please <a href = '/car-insurance/login.aspx'><b>Click Here</b></a> or Click <b>Sign In</b> again!<br/><br/>";
            //_footer += "<b>Click to send Feed Back :</b> <a href='mailto:kyawthant.phyo@teledirect.com.sg;simmonds.philip@teledirect.com.sg?subject=Car Insurance Feed Back - CompareXpress.com'>Site Admin</a>";
            _footer += "<b>Click to send Feed Back :</b> <a href='userfeedback.aspx'>Site Admin</a>";
            //ClearCarSession();
        }
        else if (ErrorCode == "911")
        {
            _header = "CompareXpress Feedback";
            _body = "Your feedback has been sent!";
            _footer = "Thank you very much for you feedback.<br /> <br /> <b>CompareXpress Team<b>";

            //ClearCarSession();
        }
        else if (ErrorCode == "199")
        {
            _header = "CompareXpress Password Recovery";
            _body = "Password recovery information has been sent to your email. Please check email inbox now.";
            _footer = "Please <a href = '../login.aspx'><b>click here</b></a> or <b>Sign In</b> to start requesting our service!";
            //ClearAllSession();
        }
        else if (ErrorCode == "1991")
        {
            _header = "CompareXpress Membership Service";
            _body = "New Password has been changed.";
            _footer = "Please <a href = '../login.aspx'><b>click here</b></a> or <b>Sign In</b> to start requesting our service!";
            //ClearAllSession();
        }
        else if (ErrorCode == "1992")
        {
            _header = "CompareXpress Membership Service";
            _body = "New Password has been reset.";
            _footer = "Please <a href = '../login.aspx'><b>click here</b></a> or <b>Sign In</b> to start requesting our service!";
            //ClearAllSession();
        }
        else if (ErrorCode == "1993")
        {
            _header = "CompareXpress Membership Service";
            _body = "Please try again later. Your session has been locked!";
            _footer = "Please <a href = '../login.aspx'><b>click here</b></a> or <b>Sign In</b> to start requesting our service!";
            //ClearOtherSession();
        }

        CE.Global.General.ClearAllSession(this.Page, "ALL");
    }

    private void ClearAllSession()
    {
        Session[CE.Global.General.UserId] = null;
        Session[CE.Global.General.UserTypeId] = null;
        Session[CE.Global.General.UserEmail] = null;
        Session[CE.Global.General.UserICNumber] = null;
        Session[CE.Global.General.CarId] = null;
        Session[CE.Global.General.CarPolicyId] = null;
        Session[CE.Global.General.CarMoreDetailId] = null;
        Session[CE.Global.General.CarResultId] = null;

        Session.Abandon();
    }

    private void ClearOtherSession()
    {
        Session["salt"] = null;
    }

    private void ClearCarSession()
    {
        Session[CE.Global.General.CarId] = null;
        Session[CE.Global.General.CarPolicyId] = null;
        Session[CE.Global.General.CarMoreDetailId] = null;
        Session[CE.Global.General.CarResultId] = null;
    }

    private void ClearHFSession()
    {
        Session[CE.Global.General.HFEmail] = null;
        Session[CE.Global.General.HFId] = null;
        Session[CE.Global.General.HFPhoneNo] = null;
        Session[CE.Global.General.HFResultId] = null;
        Session[CE.Global.General.HFUserName] = null;
        Session[CE.Global.General.LoginHistoryId] = null;
    }

    protected void btnBack_Click(object sender, EventArgs e)
    {
        //if (Session["FromSummary"] != null)
        //{
        //    if (Session["FromSummary"].ToString().Trim() == "1")
        //    {
        //        Response.Redirect("~/car-insurance/results-new.aspx");
        //    }
        //    else
        //    {
        //        Response.Redirect("~/car-insurance/results-details.aspx");
        //    }
        //}
        //else
        //{
        //    Response.Redirect("~/car-insurance/results-new.aspx");
        //}

        Response.Redirect("~/default.aspx");
    }

}

